package engine.newUi
{
	import engine.control.ControlCreater;
	import engine.control.MenuList;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.Record;
	import engine.display.newAttack.vo.FriendVo;
	import engine.flag.GameDefine;
	import engine.flag.ResourcesPath;
	import engine.logic.DoubleClickManager;
	import engine.logic.login.BlurTX;
	import engine.net.datatype.WString;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.ui.AlertUI;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	
	import flashx.textLayout.container.ScrollPolicy;
	
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.tab.NxTabEvent;
	import newx.com.control.window.NxWindowEvent;
	import newx.utils.FilterUtil;
	
	
	/**
	 * 好友逻辑 
	 * @author liuel
	 * 
	 */	
	public class FriendLogic
	{
		private const COLOR_TABLE	:Array	=	["","#ffffff'>","#1eff00'>","#0070dd'>","#a335ee'>","#ff8000'>","#e5cc80'>","#ffff00'>","#ff0000'>","#9d9d9d'>"];
		private static var _self			:FriendLogic;
		public 	 var		_ui         	:FriendUI;
		private var 		_model    		:ModelLocator;
		private var 		_bindManage		:BindManage;	
		private var 		_friendBack     :int      = -1;
		private var 		_blackListBack  :int      = -1;
		
		private var 		_petclueIndex	:int	  =-1;
		/**每日可打他宠物线索次数**/
		private var 		_totalTimes		:int =0;
		/**剩余打探次数**/
		private var 		_clueoverplus		:int =0;
		//好友列表
		private var		_friendArr  	:Vector.<FriendVo>;
		//临时好友列表
		private var       _temporaryArr	:Vector.<FriendVo>;
		//黑名单列表
		private var 		_blackArr   	:Vector.<FriendVo>;
		//私聊玩家的名字
		private var 		_socialityName  :String;
		//Table状态
		private var 		_type           :int;
		private var 		_picMC			:MovieClip;
		private var       _picMC1			:MovieClip;
		private var       _img				:NxClip;
		private var       _vo				:FriendVo;
		private var       _stateMC			:MovieClip;
		private var 		_glow:GlowFilter = new GlowFilter(0x8c8c8c, 0.5, 1, 1, 5, BitmapFilterQuality.LOW);
		private var 	  _doubleClickManager	: 	DoubleClickManager;
		//存放申请添加好友
		private var	  _nameArr				:Array =[];
		public static function getInstance():FriendLogic
		{
			if(_self == null)
			{
				_self =new FriendLogic();
			}
			return _self;
		}
		public function FriendLogic()
		{
			
		}
		/**
		 *当完成初始化后调用 
		 */		
		public function Init():void
		{
			
			_ui          = FriendUI.getInstance();
			_bindManage   = BindManage.getInstance();
			_model        = ModelLocator.getInstance();
			_friendArr    = new Vector.<FriendVo>();
			_temporaryArr = new Vector.<FriendVo>();
			_blackArr	  = new Vector.<FriendVo>();
			_ui.scrollPanel	.addView(_ui.viewGroup);
			//			_ui.scrollPanel.width =250;
			//			_ui.scrollPanel.width =250;
			_ui.scrollPanel.vscroll = 0;
			initGroup(_ui.picGroup);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_REQUEST),onAddFrid);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FRIEND_CLUE_TIEMS_PER_DAY),getTimes);
			initTab();
			_doubleClickManager	= DoubleClickManager.getInstance();
			_doubleClickManager.addDoubleClick( FriendLogic, singleClick, doubleClick );
			
		}
		
		public function	BeforeShow():void
		{
			bind();
			setSelfInfo();
			addListener();
			showMySociality();
			_ui.scrollPanel.vscroll = 0;
		}
		public function	AfterHide():void
		{
			unBind();
			removeListener();
			clearFriendAndBlack();
		}
		private function showMySociality():void
		{
			if(0 == _type)
			{		
				_ui.btnAdd           .label =StaticIni.getSwfLangStr("UIString_1000082");
				restGroup(_ui.viewGroup,_friendArr);
			}
			else if(1 == _type)
			{
				_ui.btnAdd           .label =StaticIni.getSwfLangStr("UIString_1000082");
				restGroup(_ui.viewGroup,_temporaryArr);
			}
			else if(2 == _type)
			{
				_ui.btnAdd           .label =StaticIni.getSwfLangStr("UIString_1000083");
				restGroup(_ui.viewGroup,_blackArr);
			}
			updateOnlineNum();
		}
		
		private function setClueTimes():void
		{
			var times:int=_model.scene.Role.GetProperties("FriendClueTimes");
			
		}
		private function initTab():void
		{
			_ui.socialityTab.clearItems();
			_ui.socialityTab.addItem(StaticIni.getSwfLangStr("Society_Friend"));
			_ui.socialityTab.addItem(StaticIni.getSwfLangStr("UIString_1000105"));
			_ui.socialityTab.addItem(StaticIni.getSwfLangStr("Society_Black"));
			
		}
		private function initGroup(group:NxViewGroup):void
		{
			var lenth:int 	=	group.col*group.row;
			for(var i:int=0;i<lenth;i++)
			{
				_picMC1 = group.getItemByIndex(i);
				_img				=	new NxClip();
				_img.x =_picMC1["img2"].x;
				_img.y =_picMC1["img2"].y;
				
				_picMC1.addChild(_img);
				_picMC1["img1"] = _img;
				_picMC1["titleTxt2"].text ="";
				_picMC1["titleTxt3"].text ="";
				_picMC1["infoTxt4"].width = 60;
				_picMC1["infoTxt4"].text ="";
				_picMC1["infoTxt5"].text ="";
				_picMC1["img1"].source = "";
			}
		}
		private function bind():void
		{
			if(_friendBack == -1)
			{
				_friendBack   = _bindManage.BindRecord(_model.scene,"Friend",addFirend,removeFriend);
			}
			if(_blackListBack == -1)
			{
				_blackListBack = _bindManage.BindRecord(_model.scene,"BlackList",addBlack,removeBlack);
			}
			if(_petclueIndex ==-1)
			{
				_petclueIndex =_bindManage.BindProp(_model.scene.Role,"FriendClueTimes",this,"cluetimes");
			}
		}
		private function unBind():void
		{
			if(_friendBack != -1)
			{
				_friendBack    = _bindManage.UnbindRecord("Friend",_friendBack);
			}
			if(_blackListBack != -1)
			{
				_blackListBack = _bindManage.UnbindRecord("BlackList",_blackListBack);
			}
			if(_petclueIndex !=-1)
			{
				_petclueIndex =_bindManage.UnbindProp(_model.scene.Role,"FriendClueTimes",_petclueIndex);
			}
		}
		/**
		 *获取每日可打探宠物线索次数 
		 * @param e
		 * 
		 */		
		private function getTimes(e:CustomMsgEvent):void
		{
			_totalTimes = e.pList[0];
		}
		/**
		 *已打探次数 
		 * @param value
		 * 
		 */		
		public function set cluetimes(value:int):void
		{
			_clueoverplus= _totalTimes-value;
			if(_clueoverplus<0)
				_clueoverplus=0;
		}
		private function addListener():void
		{
			_ui.windowBG         .addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			_ui.socialityTab     .addEventListener(NxTabEvent.TAB_CLICK,      onClickTab);
			_ui.btnAdd           .addEventListener(MouseEvent.CLICK,          onClickaddfriend);
			
		}
		private function removeListener():void
		{
			_ui.windowBG         .removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			_ui.socialityTab     .removeEventListener(NxTabEvent.TAB_CLICK,      onClickTab);
			_ui.btnAdd           .removeEventListener(MouseEvent.CLICK,          onClickaddfriend);
			
		}
		private function onAddFrid(e:CustomMsgEvent):void
		{
			var name:String = e.pList[1];
			var index:int=_nameArr.indexOf(name);
			if(index == -1)
			{
				if(e.pList[0] ==GameDefine.REQUESTTYPE_FRIEND )
				{
					_nameArr.push(name);
				}
				
			}
			checkFriend();
		}
		private function checkFriend():void
		{
			if(_nameArr.length >0)
			{
				AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000084"),StaticIni.getSwfLangStrVar("UIString_1000078",[_nameArr[0]]),AlertUI.YES|AlertUI.NO,backFunc,[_nameArr[0]]);
			}
		}
		private function backFunc(type:int,str:String,clickData:*):void
		{
			if(AlertUI.YES == type)//同意添加好友
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_ANSWER,GameDefine.REQUESTTYPE_FRIEND,new WString(clickData[0]),1);	
			}
			else   //拒绝添加
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_ANSWER,GameDefine.REQUESTTYPE_FRIEND, new WString(clickData[0]),0);
			}
			var index:int= _nameArr.indexOf(clickData[0]);
			if(index !=-1)
			{
				_nameArr.splice(index,1);
			}
			checkFriend();
		}
		/**
		 * 根据数据获取一个玩家 
		 * @param val    在线状态(0不在线1在线)   1性别(1女2男)    2等级   3模型好
		 * @param type  1 好友列表获取  2黑名单列表获取 3 其他获取
		 * @return 
		 * 
		 */		
		public function getOneUser(val:Array,type:int):FriendVo
		{
			var name:String	= val[0];
			var state:int;//在线状态
			var sex	 :int;//性别
			var level:int;//等级ID
			var modeId:int; //模型号
			var clotheModel:int; //服装号
			if(type == 1)
			{
				state	= val[6];  
				sex		= val[11]; 
				level	= val[5];
				modeId	= val[10];
				clotheModel=val[14];
			}
			else if(type == 2)
			{
				state= val[5];
				sex  = val[10];
				level	 = val[4];
				modeId	= val[9];
				clotheModel=val[12];
			}
			else if(type  == 3)
			{
				
				state	= val[1];  
				sex		= val[2]; 
				level	= val[3];
				modeId	= val[4];
				clotheModel=val[5];
			}
			var userVo:FriendVo = new FriendVo(name,state,sex,level,modeId,clotheModel);
			return userVo;
		}
		/**
		 * 根据名字搜索时不是自己好友 
		 * @param name
		 * @return 
		 * 
		 */	 
		public function byNameckeckFriend(name:String):Boolean
		{
			for(var i:int =0;i<_friendArr.length;i++ )
			{
				if(_friendArr[i].name ==name)
				{
					
					return true;
				}
			} 
			return false;
		}
		
		public function byNameckeckBlack(name:String):Boolean
		{
			for(var i:int =0;i<_blackArr.length;i++ )
			{
				if(_blackArr[i].name ==name)
				{
					
					return true;
				}
			}
			return false;
		}
		/**
		 * 保存所有好友 
		 * @param vo
		 * 
		 */			
		private function saveFriendUser(vo:FriendVo):void
		{
			if(vo == null)
				return ;
			for(var i:int =0;i<_friendArr.length;i++ )
			{
				if(_friendArr[i].name == vo.name)
				{
					_friendArr[i] = vo;
					taxisFunc(_friendArr);
					updateFriendList();
					return;
				}
			}
			_friendArr.push(vo);
			taxisFunc(_friendArr);
			updateFriendList();
		}
		/**
		 * 删除一个好友 
		 * @param vo
		 * 
		 */		
		private function deleOneFriendUser(vo:FriendVo):void
		{
			for(var i:String  in  _friendArr)
			{
				if(_friendArr[i].name ==vo.name )
				{
					_friendArr.splice(int(i),1);
				}
			}
			taxisFunc(_friendArr);
			updateFriendList();
			
		}
		/**
		 *更新好友列表 
		 * 
		 */		
		private function updateFriendList():void
		{
			var friend:Record= _model.scene.GetRecordEx("Friend");
			if(friend.recArr.length==_friendArr.length)
			{
				showMySociality();
			}
		}
		/**
		 * 添加最近联系人 
		 * @param vo
		 * 
		 */		
		public function saveTemporaryUser(vo:FriendVo):void
		{
			for(var i:int=0;i<_temporaryArr.length;i++)
			{
				if(_temporaryArr[i].name  == vo.name)
					return ;
			}
			_temporaryArr.push(vo);
		}
		/**
		 *更新黑名单列表 
		 * 
		 */		
		private function updateBlackList():void
		{
			var black:Record= _model.scene.GetRecordEx("BlackList");
			if(black.recArr.length==_blackArr.length)
			{
				showMySociality();
			}
		}
		
		/**
		 * 删除一个黑名单 
		 * @param vo
		 * 
		 */		
		private function deleOneBlackUser(vo:FriendVo):void
		{
			for(var i:String  in  _blackArr)
			{
				if(_blackArr[i].name ==vo.name )
				{
					_blackArr.splice(int(i),1);
				}
			}
			taxisFunc(_blackArr);
			updateBlackList();
			
		}
		private function clearFriendAndBlack():void
		{
			_friendArr    = new Vector.<FriendVo>();
			restGroup(_ui.viewGroup,_friendArr);
		}
		
		/**
		 * 保存所有的黑名单 
		 * @param vo
		 * 
		 */		
		private function saveBackUser(vo:FriendVo):void
		{
			if(vo == null)
				return ;
			for(var i:int=0;i<_blackArr.length;i++)
			{
				if(_blackArr[i].name == vo.name)
				{
					_blackArr[i] = vo;
					updateBlackList();
					return;
				}
			}
			_blackArr.push(vo);
			updateBlackList();
		}
		/**
		 * 更新好友 
		 * @param val
		 * 
		 */		
		private function updataFirend(val:Array):void
		{
			var vo:FriendVo = getOneUser(val,1);
			saveFriendUser(vo);
		}
		/**
		 * 重置Group 
		 * @param group   对象
		 * @param userarr 用户数组
		 * 
		 */		
		private function restGroup(group:NxViewGroup,userarr:Vector.<FriendVo>):void
		{
			
			if(userarr.length != group.row)
			{
				var skin:String=group.viewSkin;
				var scrskin:String=_ui.scrollPanel.vScrollSkin;
				var width:int=_ui.border.width+100;
				var height:int=_ui.border.height;
				var col:int=group.col;
				var row:int=userarr.length;
				var pa:DisplayObjectContainer=group.parent;
				pa.removeChild(group)
				_ui.scrollPanel.removeView(group);
				_ui.viewGroup.removeItemsEvent(MouseEvent.CLICK,onClickGroup);
				group=null;
				//					_ui.scrollPanel=null
				//创建
				//					_ui.scrollPanel=ControlCreater.getInstance().CreateScrollPanelEx(width,height,[scrskin]);
				_ui.viewGroup=ControlCreater.getInstance().CreateNxViewGroup(row,1,skin);
				_ui.viewGroup.addItemsEvent(MouseEvent.CLICK,onClickGroup);
				group =_ui.viewGroup;
				//					_ui.scrollPanel.x=_ui.border.x
				//					_ui.scrollPanel.y=_ui.border.y
				//				pa.addChild(_ui.scrollPanel);
				pa.addChild(group);
				updateGroup(group,userarr);
				if(group == _ui.viewGroup)
				{
					_ui.scrollPanel.verticalScrollPolicy=ScrollPolicy.AUTO;
					_ui.scrollPanel.vscroll = 0;
					_ui.scrollPanel.addView(group);
				}
				
			}
			else
			{
				updateGroup(group,userarr);
			}
		}
		/**
		 * 更新Group  
		 * @param group
		 * @param arr    
		 * 
		 */		
		private function updateGroup(group:NxViewGroup,arr:Vector.<FriendVo>):void
		{
			var lenth:int 	=	group.col*group.row;	
			var state:int =0;
			var name:String ;
			var levStr:String;
			for(var i:int=0;i<lenth;i++)
			{
				_picMC = group.getItemByIndex(i);
				state =arr[i].state;
				setMcState(arr[i].sex,state,_picMC);
				if(state ==0)
				{
					name =arr[i].name;
					levStr =StaticIni.getSwfLangStrVar("UIString_1000036",[arr[i].level]);
				}
				else
				{
					name =link_color(arr[i].name,1);
					levStr =link_color(StaticIni.getSwfLangStrVar("UIString_1000036",[arr[i].level]),5)
				}
				_picMC["titleTxt2"].htmlText =name+"   "+levStr;
				(_picMC["titleTxt2"] as TextField).filters = (state ==0)?[FilterUtil.GrayColorFilter]:null
				_picMC["date"] = arr[i];
				
			}
		}
		/**
		 * 根据性别状态设置MC 
		 * @param sex
		 * 
		 */		
		private function setMcState(sex:int,state:int,mc:MovieClip):void
		{
			//离线
			if(state == 0)
			{
				mc["img"].gotoAndStop(1);
			}
			else
			{
				//男
				if(sex == 1)
				{
					mc["img"].gotoAndStop(3);
				}//女
				else
				{
					mc["img"].gotoAndStop(2);
				}
			}
		}
		/**
		 * 更新黑名单 
		 * @param val
		 * 
		 */		
		private function updataBlack(val:Array):void
		{
			var vo:FriendVo =getOneUser(val,2);
			saveBackUser(vo);
		}
		private var _bl:BlurTX=new BlurTX;
		/**
		 * 更新收到消息的好友状态 
		 * @param str
		 * 
		 */		
		public function udateGetMsgFriend(name:String):void
		{
			//切到好友列表
			if(_type!=0) _type =0;
			showMySociality();
			
			var mc:MovieClip = getVieGroupMC(name);
			if(mc!=null)
			{
				mc.filters = [ FilterUtil.WhiteGlowFilter ];
				
			}
			
		}
		/**
		 *根据好友名字获取所在Group的MC 
		 * @param name
		 * @return 
		 * 
		 */		
		private function getVieGroupMC(name:String):MovieClip
		{
			var mc:MovieClip;
			var index:int =-1;
			for(var i:int=0;i<_friendArr.length;i++)
			{
				if(name == _friendArr[i].name)
				{
					index = i;
				}
			}
			if(i != -1)
			{
				mc = _ui.viewGroup.getItemByIndex(index);
			}
			else
			{
				mc= null;
			}
			
			return mc;
		}
		/**
		 *设置自己信息 
		 * 
		 */		
		private function setSelfInfo():void
		{
			var level:int = _model.scene.Role.getPlayerLevel();
			_picMC1["titleTxt2"].htmlText =link_color(_model.scene.Role.getPlayerName(),1);
			_picMC1["titleTxt3"].htmlText =link_color(StaticIni.getSwfLangStrVar("UIString_1000036",[level]),5) ;
			var clothModel:int=0;
			clothModel=_model.scene.Role.clotheModel;
			_picMC1["img1"].source = ResourcesPath.getMiniHeadPic(int(_model.scene.Role.ModelId),clothModel);
		}
		/**
		 *更新在线好友数 
		 * 
		 */		
		private function updateOnlineNum():void
		{
			var numstr:String = getOnLineNum()+"人";
			_picMC1["infoTxt4"].htmlText =StaticIni.getSwfLangStr("UIString_1000087")+numstr;
		}
		/**
		 * 获得好友在线人数 
		 * @return 
		 * 
		 */		
		private function getOnLineNum():int
		{
			var num:int;
			for(var i:int;i<_friendArr.length;i++)
			{
				if(_friendArr[i].state == 1)
				{
					num++;
				}
			}
			return num;
		}
		/**
		 * 获取玩家当前副本进度 
		 * @return 
		 * 
		 */		
		private function getSelfCurrFb():String
		{
			var list:Record = _model.scene.GetRecordEx("CompletedFB");
			var id :int = list.recArr[list.recArr.length-1];
			id ==0? id=11000201 :id=id;
			var str:String = StaticIni.getSwfLangStr(id.toString()); 
			return str;
		}
		/**
		 *私聊接口   
		 * @param vo 私聊的对象    
		 * 
		 */		
		public function WhispChat(vo:FriendVo):void
		{
			WhisperLogic.getInstance().Whispername=vo;
			if(WhisperLogic.getInstance().whisperUi.created ==false)
			{
				WhisperLogic.getInstance().whisperUi.showOrHide();
			}
			else
			{
				WhisperLogic.getInstance().updateUI();
			}
			
			saveTemporaryUser(vo);
		}
		/**
		 * 点击的是好友弹出菜单 
		 * @param index
		 * @param data
		 * 
		 */		
		private function onFriendClick(index:uint,vo:FriendVo):void
		{
			
			var name:String	= vo.name;
			var needLv:String =StaticIni.getIniVar("TopOther_Need","lvl4");
			
			if(!isHave)
			{
				if(index>1)
					index ++;
			}
			switch(index)
			{
				//私聊
				case 0:
					WhispChat(vo);
					break;
				//查看
				case 1:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_LOOK_EQUIPS,new WString(name));
					break;
				case 2:
					if(vo.level>=int(needLv))
					{
						//请求推演运功
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_COUPLE_AFK_REQUEST,new WString(name));
					}
					else
					{
						//对方不满足
						NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStrVar("UIString_1000397",[needLv]));
					}
					break;
				//				//打探
				//				case 3:
				//					if(BottomIndexLogic.getInstance().petBtnState)
				//					{
				//						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FRIEND_CLUE,new WString(name));
				//						//好友打探
				//						
				//					}
				//					else
				//					{
				//						index++;
				//						onFriendClick(index,vo)
				//					}
				//					break;
				
				//				case 3:
				//					DigCimeliaLogic.getInstance().ui.showOrHide();
				//					break;
				//删除
				case 3:
					AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000084"),StaticIni.getSwfLangStrVar("UIStr_1000832",[_socialityName]),AlertUI.YES|AlertUI.NO,
						onDeleteFriend,[_socialityName],false,300,150);
					break;
				//加入黑名单
				case 4:
					AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000084"),StaticIni.getSwfLangStrVar("UIString_1000086",[_socialityName]),AlertUI.YES|AlertUI.NO,
						onAddBlackNameBack,[_socialityName],false,300,150);
					break;
			}
		}
		/**
		 * 点击的是最近联系人弹出菜单
		 * @param index
		 * @param data
		 * 
		 */		
		private function onTemporarylistClick(index:uint,vo:FriendVo):void
		{
			var name:String = vo.name;
			switch(index)
			{
				//私聊
				case 0:
					WhispChat(vo);
					break;
			}
			
		}
		/**
		 * 点击的是黑名单弹出菜单
		 * @param index
		 * @param data
		 * 
		 */		
		private function onBlacklistClick(index:uint,vo:FriendVo):void
		{
			var name:String = vo.name;
			switch(index)
			{
				//移出
				case 0:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_BLACKLIST_REMOVE, new WString(name));	
					break;
			}
			
		}
		///////////////////////////////////回调函数///////////////////////////////////////////////
		//添加好友
		private function addFirend(PropertiesName:String,val:*,data:*):void
		{
			updataFirend(val);
		}
		//删除好友
		private function removeFriend(PropertiesName:String,PropertiesValue:*,data:*):void
		{
			var vo:FriendVo = getOneUser(PropertiesValue,1);
			deleOneFriendUser(vo);
		}
		//添加黑名单
		private function addBlack(PropertiesName:String,val:*,data:*):void
		{
			updataBlack(val);
		}
		//删除黑名单
		private function removeBlack(PropertiesName:String,PropertiesValue:*,data:*):void
		{
			var vo:FriendVo = getOneUser(PropertiesValue,2);
			deleOneBlackUser(vo);
		}
		/**
		 * 添加好友回调 
		 * @param type
		 * @param str
		 * @param clickData
		 * 
		 */		 
		private function onAddFriendBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.OK == type)//添加好友
			{
				sendAddFriend(str);
			}
		}
		/**
		 * 申请添加好友 
		 * @param name 名字
		 * 
		 */		
		public function sendAddFriend(name:String):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST,GameDefine.REQUESTTYPE_FRIEND, new WString(name));	
		}
		/**
		 * 申请添加黑名单 
		 * @param name 名字
		 * 
		 */		
		public function sendAddBlack(name:String):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_BLACKLIST_ADD, new WString(name));	
		}
		/**
		 * 删除好友回调 
		 * @param clickName
		 * @param inputTxt
		 * @param clickData
		 * 
		 */		
		private function onDeleteFriend(clickName:uint,inputTxt:String,clickData:Array):void
		{
			if(clickName==AlertUI.YES)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FRIEND_REMOVEROLE, new WString(clickData[0]));	
			}
		}
		/**
		 * 添加黑名单回调 
		 * @param type
		 * @param str
		 * @param clickData   点击的
		 * 
		 */			
		private function onAddBlackNameBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.OK == type || AlertUI.YES == type)
			{
				sendAddBlack(clickData[0]);
			}
			
		}
		/**
		 * 添加黑名单回调 
		 * @param type
		 * @param str
		 * @param clickData
		 * 
		 */			
		private function onAddBlackNameBack1(type:int, str:String, clickData:*):void
		{
			if(AlertUI.OK == type)
			{
				sendAddBlack(str);
			}
			
		}
		/**
		 * 删除黑名单回调 
		 * @param type
		 * @param str
		 * @param clickData
		 * 
		 */		
		private function onDeleteBlackNameBakc(clickName:int, str:String, clickData:Array):void
		{
			if(AlertUI.YES == clickName)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_BLACKLIST_REMOVE, new WString(clickData[0]));	
			}
		}
		
		/**
		 * 点击菜单回调 
		 * @param index
		 * @param data
		 * 
		 */		
		private function onFuncClick(index:uint,vo:FriendVo):void
		{	
			
			if(0 == _type)
			{
				onFriendClick(index,vo);
			}
			else if(1 == _type) //临时好友
			{
				onTemporarylistClick(index,vo);
			}
			else if(2 == _type)
			{
				onBlacklistClick(index,vo);
			}
			
		}
		private function taxisFunc(arr:Vector.<FriendVo>):void
		{
			var arr1:Vector.<FriendVo> = null;
			arr = arr.sort(byStateFunc);
		}
		private function byStateFunc(vo1:FriendVo,vo2:FriendVo):int
		{
			var vo:FriendVo;
			return -(vo1.state-vo2.state);
		}
		private function link_color(str:String,color:int):String
		{
			if(color < 1 || color >8)
			{
				color	=	1;
			}
			return ("<font color ='"+COLOR_TABLE[color]+str+"</font>");
		}
		///////////////////////////////////监听函数//////////////////////////////////////////////
		private function onClickClose(e:NxWindowEvent):void
		{
			_ui.showOrHide();
		}
		private function onClickTab(e:NxTabEvent):void
		{
			_type =_ui.socialityTab.selected;
			showMySociality();
		}
		private function onClickGroup(e:MouseEvent):void
		{
			_doubleClickManager.onClick( FriendLogic, e );
		}
		private var isHave:Boolean;
		private function singleClick( evt : MouseEvent ):void
		{
			var mc:MovieClip =evt.target.parent as MovieClip;
			if(mc ==null) return;
			if(_stateMC !=null)
			{
				_stateMC.gotoAndStop(1);
				if(mc.currentFrame ==1)
				{
					mc.gotoAndStop(2);
				}
			}
			else
			{
				mc.gotoAndStop(2);
			}
			_stateMC = mc;
			if(mc == null)
				return ;
			var friend:FriendVo = mc.date;
			var name:String = friend.name;
			var menuItemList:Array = [];
			
			if(0 == _type)
			{
				//私聊
				menuItemList.push(StaticIni.getSwfLangStr("Common_Whisper"));
				//查看
				menuItemList.push(StaticIni.getSwfLangStr("Common_Watch"));
				var needLv:String =StaticIni.getIniVar("TopOther_Need","lvl4");
				if(_model.scene.Role.getPlayerLevel()>=int(needLv) && friend.state ==1)
				{
					//推演运功
					menuItemList.push(StaticIni.getSwfLangStr("UIString_1000550"));
					isHave =true;
				}
				else
				{
					isHave =false;
				}
				
				//				if(BottomIndexLogic.getInstance().petBtnState)
				//				{
				//					//好友打探
				//					menuItemList.push(StaticIni.getSwfLangStrVar("UIString_1000435",[_clueoverplus]));
				//				}
				
				//				//赠送宝物
				//				menuItemList.push(StaticIni.getSwfLangStr("UIString_1000261"));
				//删除好友
				menuItemList.push(StaticIni.getSwfLangStr("UIStr_1000349"));
				//加入黑名单
				menuItemList.push(StaticIni.getSwfLangStr("UIString_1000081"));
				
			}
			else if(1 == _type) //临时好友
			{
				//私聊
				menuItemList.push(StaticIni.getSwfLangStr("Common_Whisper"));
			}
			else if(2 == _type)
			{
				//移出黑名单
				menuItemList.push(StaticIni.getSwfLangStr("UIString_1000100"));
			}
			MenuList.ShowMenu(menuItemList,onFuncClick,friend);
			_socialityName = name;
			name       = null;
		}
		private function doubleClick( evt : MouseEvent ):void
		{
			var mc:MovieClip =evt.currentTarget as MovieClip;
			if(_stateMC !=null)
			{
				_stateMC.gotoAndStop(1);
				if(mc.currentFrame ==1)
				{
					mc.gotoAndStop(2);
				}
			}
			else
			{
				mc.gotoAndStop(2);
			}
			_stateMC = mc;
			if(mc == null)
				return ;
			var friend:FriendVo = mc.date;
			WhispChat(friend);
			
		}
		public function get CanWhisperAndFriend():Boolean
		{
			//			var currLevel:int=_model.scene.Role.getPlayerLevel();
			if(BottomIndexLogic.getInstance()._buddyBtn.visible==false)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		public function addBlackFunc(name:String):void
		{
			AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000084"),StaticIni.getSwfLangStrVar("UIString_1000086",[name]),AlertUI.YES|AlertUI.NO,
				onAddBlackNameBack,[name],false,300,150);
		}
		/**
		 * 点击添加好友 
		 * @param e
		 * 
		 */		
		private function onClickaddfriend(e:MouseEvent):void
		{
			if(_ui.btnAdd.label == StaticIni.getSwfLangStr("UIString_1000082"))
			{
				AlertUI.showAlert(StaticIni.getSwfLangStr("UIStr_1000348"),"",AlertUI.OK|AlertUI.CANCEL,onAddFriendBack,null,true);
			}
			else if(_ui.btnAdd.label ==StaticIni.getSwfLangStr("UIString_1000083"))
			{
				AlertUI.showAlert(StaticIni.getSwfLangStr("UIStr_1000351"),"",AlertUI.OK|AlertUI.CANCEL,onAddBlackNameBack1,null,true);
			}
			
		}
		
	}
}